﻿using B.S.Base.ErrorCode;
using B.S.Base.Infrastructrue;
using B.S.Base.Moain.Entities;
using B.S.Base.Read.Api.Application.Command.Shops;
using MediatR;

namespace B.S.Base.Read.Api.Application.CommandHander.Shops
{
    public class ShowShopCommandHander : IRequestHandler<ShowShopCommand, APIResult<List<Shop>>>
    {
        private readonly IBaseRepository<Shop> shop;

        public ShowShopCommandHander(IBaseRepository<Shop> shop)
        {
            this.shop = shop;
        }

        
            
        public Task<APIResult<List<Shop>>> Handle(ShowShopCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<Shop>> result = new APIResult<List<Shop>>();
            var list = shop.GetAll().Result.OrderBy(x => x.ShopId).ToList();
            result.Code = APIEnum.查询成功;
            result.Msg = APIEnum.查询成功.ToString();
            result.data = list.ToList();
            return Task.FromResult(result);
        }
    }
}
